﻿namespace dotnet_notes.Extensions
{
    /// <summary>
    /// HttpContext 扩展类
    /// </summary>
    public static class HttpContextExtension
    {
        /// <summary>
        /// 获取指定请求头的值
        /// </summary>
        /// <param name="httpContext"></param>
        /// <param name="headerKey">请求头 key</param>
        /// <returns></returns>
        public static string GetHeader(this HttpContext httpContext, string headerKey)
        {
            return httpContext.Request.Headers[headerKey].ToString();
        }

        /// <summary>
        /// 获取远程连接 IP
        /// </summary>
        public static string GetRemoteIp(this HttpContext httpContext)
        {
            return httpContext.Connection.RemoteIpAddress?.ToString() ?? "";
        }
    }
}
